﻿using DevTeam;
using System.Data;

namespace ConfExpert.Forms.ImportWizards
{
    public partial class XIBOM : XImportWizard
    {
        public XIBOM()
        {
            InitializeComponent();

            this.ProcessStart += XIBOM_ProcessStart;
            this.ProcessDone += XIBOM_ProcessDone;
            btnSave.ItemClick += BtnSave_ItemClick;
        }

        public DataTable dt;
        private void BtnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            string Sezon = bbiSezon.EditValue.ToStr();
            if (Sezon == "")
            {
                ShowErrorMessage("Sezon boş olamaz");
                return;
            }

            DataSet ds = MasterGrid.Dataset();
            
            string str1 = ds.Tables[0].Serialize();
            string str2 = ds.Tables[1].Serialize();

            ExecuteNonQuery("ImportBOM", str1, str2, Sezon);
            ShowInfoMessage("Aktarma işlemi tamamlandı.");
            BOM.Clear();
            BOMLines.Clear();
            btnSave.Enabled = false;
        }

        void XIBOM_ProcessDone()
        {
            splitter.PanelVisibility = DevExpress.XtraEditors.SplitPanelVisibility.Panel1;
            MasterGrid.Init(BOMLines);

            btnSave.Enabled = true;
            MasterGrid.AddSummary();
            MasterGrid.MakeReadOnly();
            MasterGrid.BestFitColumns();
        }

        void XIBOM_ProcessStart()
        {
            Result = new DataSet();
            BOM = new DataTable();
            BOMLines = new DataTable();
            Result.Tables.Add(BOM);
            Result.Tables.Add(BOMLines);

            foreach (string s in "DosyaAdi,Style,Phase,Division,MaterialNr,Brand".Split(",".ToCharArray()))
                BOM.Columns.Add(s, typeof(string));

            foreach (string s in "DosyaAdi,ItemNr,Material,MaterialDescription,ItemText1,UsageDescription,CADInd,CompQuantity,Unit,FixColor,Color1,Color2,Color3,Color4,Color5,Color6,Color7,Color8,Color9,Color10,Color11,Color12,Color13,Color14,Color15,FixSize,VendorMaterialNumber,VendorName,MP".Split(",".ToCharArray()))
                BOMLines.Columns.Add(s, typeof(string));
        }


        public DataTable BOM;
        public DataTable BOMLines;
        public DataSet Result;

        private void XIBOM_Load(object sender, System.EventArgs e)
        {
            //if (!DesignMode)
        }

    }


}
